<template>
  <el-main>
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="合同名称">
        <el-input v-model="queryForm.name" placeholder="合同名称" clear></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="query">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
        :data="tableData"
        style="width: 100%"
        :row-class-name="tableRowClassName">
      <el-table-column
          prop="name"
          label="序号"
          width="50">
        <template slot-scope="scope">
          {{scope.$index+1}}
        </template>
      </el-table-column>
      <el-table-column
          prop="name"
          label="合同名称"
          width="180">
      </el-table-column>
      <el-table-column
          prop="date"
          label="合同日期"
          width="180">
      </el-table-column>
      <el-table-column
          prop="total"
          label="合同金额">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
              size="mini"
              type="danger"
              @click="priview(scope.row)">预览</el-button>
          <el-button
              size="mini"
              type="danger"
              @click="check(scope.row)">提交审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row>
      <el-col :span="6">
        <el-button type="primary" @click="add">添加</el-button>
        <el-button type="primary" @click="pdf">导出pdf</el-button>
      </el-col>
      <el-col :span="18">
        <el-pagination
            small
            layout="prev, pager, next"
            :page-count="page"
            @current-change="curPageChange">
        </el-pagination>
      </el-col>
    </el-row>

  </el-main>
</template>

<script>
export default {
  name: "HeTong",
  data() {
    return {
      tableData: [],
      queryForm:{
        size: 2
      },
      page: 1
    }
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    check(row) {
      this.axios.post('hetong/activiti/startProcessInstanceById', {id:row.id}).then(res => {
        this.$message.success(res.data.msg);
      });
    },
    priview(row) {
      window.open(this.axios.defaults.baseURL+'hetong/pdfDetail?id='+row.id,'_blank')
    },
    pdf() {
      window.location.href = this.axios.defaults.baseURL+'hetong/pdf';
    },
    handleEdit(index,row) {
      console.log(index, row);
      this.$router.push('/hetong/update/' + row.id);
    },
    add() {
      this.$router.push("/hetong/update/0");
    },
    query() {
      this.queryForm.current = 1;
      this.pageQuery();
    },
    curPageChange(curPage) {
      console.log(curPage);
      this.queryForm.current = curPage;
      this.pageQuery();
    },
    pageQuery() {
      this.axios.get('/hetong/page', {params: this.queryForm}).then(res => {
        this.tableData = res.data.data.records;
        this.page = res.data.data.pages;
      });
    }
  },
  mounted() {
    this.pageQuery();
  }
}
</script>

<style scoped>
.el-row {
  margin-top: 20px;
}
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>